Module Save function acting weird

Hi guys,

I've been messing around with the save function.
Here's my code snippet:
======================
Module m

void Mod_Save = save(Module m)

for m in current Project do //for all open modules inside the project, not including modules inside another project that is in this main project.
{

Object o

for o in m do
{
inherited o
}

//void Mod_Save = save(Module m) // Saves the Open module

print m."Name"": ""Saved." "\n"
bool Mod_Close = close(Module m,true) //Closes module without saving; already saved.
}
ack "All objects now inheriting access controls"
============================

The problem is that the save function, whether I put it where it is now, or inside the loop with the comment, never fails to produce a runtime error. Apparently it says "unassigned variable reference (m)".

The other function, Mod_Close doesn't cause this error.

Any clue what I can do?

Thanks,

TooDiff
TooDifficult - Sun Dec 05 17:59:24 EST 2010

Re: Module Save function acting weird
llandale - Mon Dec 06 17:00:20 EST 2010

void Mod_Save = save(Module m)

This says you want a void variable called 'Mod_Save' that gets the returned value of the existing 'save(Module m)'. That's doesn't make any sense, lets forget about that. If you were trying to define a function, you need syntax that looks like this:

VarType FunctionName(zero or more parameters like "string abc")
{  body of function
}


the braces and brackets {}() are mandatory. 'VarType' is often 'void', but if its some other type like 'string' then the body must return a 'string' value.

Perhaps you are trying to do this:

 

for m in current Project do    //for all open modules inside the project, 
                        // not including modules inside another project that is in this main project. 
{
   Object o 
   for o in m do
   {
      inherited o
   }
   save(m) // Saves the Open module
    print m."Name"": ""Saved." "\n"
 
   close(Module m,true) //Closes module without saving; already saved.
}  // end for open modules in the project.


You seem to be confusing the definition of a function in the manual with how you call the functions. The manual says:
void save(Module m).

That means 'save' is the function name, that accepts a single parameter type 'Module', and 'void' means it doesn't return anything. 'm' gives some indication what the parameter is, but since the type is 'Module' then 'm' provides no useful information.

Anyway, this code bytes. Perhaps add "if (!isEdit(m)) continue" at the top of the loop so you don't try to modify a read-only module. You do NOT want to set inherited any open mdoule anyway, you should probably run this code only from the currently open module. Skip the loop, issue "m = current" at the top. Edit a module, run the script, which inherits all its objects and NO OTHER MODULE. You also want to trap the errors, and set all the objects inherited. How about this:

 

 

Module m = current
if (null m or !isEdit(m)) {errorBox("Run from open edit module"); halt}
if (!confirm("Erase all shared sections in '" name(m) "'??")) halt
 
string ErrMess
Object o
for o in entire m do
{  noError()
   inherited(o)
   ErrMess = lastError()
   if (!null ErrMess) print (identifier(o)) "\t" ErrMess
}
save(m)
//  The user opened the module, let her close it.

 

 

  • Louie